package com.baibang.baibang815.controller;

import com.baibang.baibang815.domain.User;
import com.baibang.baibang815.service.UserService;
import com.baibang.baibang815.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private UserService userService;



    @GetMapping("/getUserById")
    @ApiOperation(value = "根据ID查询用户信息")
    public AjaxResult getUserById(@RequestParam int id) {
        // 白帮 0815
        return AjaxResult.success(userService.selectById(id));
    }

    @PostMapping("/addUser")
    @ApiOperation(value = "新增用户")
    public AjaxResult addUser(@RequestBody User user) {
        // 白帮 0815
        return AjaxResult.success(userService.saveUser(user));
    }

    @PostMapping("/updateUser")
    @ApiOperation(value = "修改用户信息")
    public AjaxResult updateUser(@RequestBody User user) {
        // 白帮 0815
        return AjaxResult.success(userService.updateUser(user));
    }

    @PostMapping("/deleteUser")
    @ApiOperation(value = "删除用户")
    public AjaxResult deleteUser(@RequestParam int id) {
        // 白帮 0815
        return AjaxResult.success(userService.deleteUser(id));
    }


}